<!DOCTYPE html>
<html>
<div class="header" style="height:500px;"></div>
<div class=col.center>
<div class="highlight" style="font-family:'Roboto Condensed, sans-serif';">
<link rel="preconnect" href="https://fonts.gstatic.com">                                                                                                                <link href="https://fonts.googleapis.com/css2?family=Inconsolata&family=JetBrains+Mono:ital,wght@1,500&display=swap" rel="stylesheet">
<link rel="stylesheet" type='text/css' href='style.php' />
  <?php
  $question =  $_GET['quest'];
  echo "<table style='border: solid 5px black; border-collapse: collapse; border-radius: 35px; font-family:Roboto Condensed, sans-serif;'>";
  echo "<tr><th>title</th><th>author</th><th>description</th><th>tags</th><th>categories</th></tr>";
  
  class TableRows extends RecursiveIteratorIterator {
      function __construct($it) {
          parent::__construct($it, self::LEAVES_ONLY);
    }

    function current() {
        return "<td style='width:500px;border:5px solid black; text-align: center; padding: 15px; border-radius: 35px;'>" .
  parent::current(). "</td>";
    }

    function beginChildren() {
        echo "<tr>";
    }

    function endChildren() {
        echo "</tr>" . "\n";
    }
  }

  $where = "localhost";
  $user = "root";
  $password = "xxxx";
  
  try {
  	$conn = new PDO("mysql:host=$where;dbname=dazed", $user, $password);
  	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $conn->prepare("SELECT title, author, description, tags, categories FROM dazed WHERE MATCH(title, author, description, tags, categories)
                           AGAINST ('$question' IN NATURAL LANGUAGE MODE)");
    $stmt->execute();
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
        echo $v;
    }
  }  
  	catch(PDOException $e) {
  	echo "Connection failed: " . $e->getMessage();
  }
  $conn = null;
  echo  "</table>";
  ?>
</div>
</div>
</html>
